import React from 'react';
import store from '../store'
import {Menu} from "antd";
import {Link} from 'react-router-dom'



function AppMenu() {
    const  userRouter = store.getState().userStore.user.route
    const items = userRouter.map((item) => {
        if(item.children && item.children.length>1){
            console.log()
            if( item.children.filter(itemD => !itemD.hidden).length>1){
                return {
                    key: item.id,
                    label: item.title,
                    children:(item.children&&item.children.length>1  && item.children.filter(itemD => !itemD.hidden).length>1)? item.children.map((itemC)  => {
                        return {
                            key: itemC.id,
                            label: <Link to={itemC.path}>{itemC.title}</Link>,
                        };
                    }):''
                };
            }else {
                return {
                    key: item.id,
                    label: <Link to={item.path}>{item.title}</Link>,
                };
            }

        }else {
            return {
                key: item.id,
                label: <Link to={item.path}>{item.title}</Link>,
            };
        }

    });
    const onopenMenuChange = (keys)=>{
        console.log(keys)
    }
    // console.log(userRouter)
    return (
        <Menu
            mode="inline"
            defaultSelectedKeys={['1']}
            defaultOpenKeys={[]}
            onClick={onopenMenuChange}
            style={{
                height: '100%',
                borderRight: 0,

                width:200,
                paddingLeft:"20px",
            }}
            items={items}
        />
    );
}

export default AppMenu;